import { createRouter, createWebHashHistory } from 'vue-router'
import webSiteRoute from './webSite'
import useElementPlusStore from '@/stores/UseElementPlusStore'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/website/home',
    },
    {
      path: '/website',
      name: 'website',
      children: webSiteRoute,
    },
    {
      path: '/404',
      name: '404',
      component: () => import('@/views/404.vue'),
    },
    //其他路由都跳转到404
    {
      path: '/:path(.*)',
      name: 'any',
      redirect: { name: '404' },
    },
  ],
  scrollBehavior() {
    return { top: 0 }
  },
})

router.beforeEach((to, from, next) => {
  useElementPlusStore().startLoad()

  next()
})

// router.afterEach(() => {
//   useElementPlusStore().closeLoad()
// })

export default router
